package com.zwr.sheller.customer.controller;

import com.github.pagehelper.PageInfo;
import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.pojo.Order;
import com.zwr.sheller.customer.Service.CustomerOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author LSY
 * @Date 2022/1/11 19:30
 * @Version 1.0
 **/
@RestController
@RequestMapping(value = "/customerOrder")
@Api(tags = "前台用户查看订单接口集")
@CrossOrigin
public class CustomerOrderController {

    CustomerOrderService customerOrderService;
    @Autowired
    public CustomerOrderController(CustomerOrderService customerOrderService) {
        this.customerOrderService = customerOrderService;
    }

    @PostMapping(value = "/findAllOrders")
    @ApiOperation(value = "查找当前登录的买家的所有订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页页数", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "num", value = "每页显示条数", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "status", value = "希望查询的订单状态", required = false, dataType = "Long"),
            @ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "Long")
    })
    public Map<String, Object> findAllOrders(Integer page, Integer num, Integer status, Long uid) {
        PageInfo<Order> info = customerOrderService.findAllOrders(page, num, status, uid);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setField("orders", info.getList());
        jsonResult.setField("count", info.getTotal());

        return jsonResult.getMap();
    }
}
